<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="12">
          <el-form-item :label="$t('证券公司')" prop="securityCompany">
            <el-input v-model="form.securityCompany" :placeholder="$t('证券公司')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('资金账户')" prop="capitalAccount">
            <el-input v-model="form.capitalAccount" :placeholder="$t('资金账户')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('沪市')" prop="huShi">
            <el-input v-model="form.huShi" :placeholder="$t('沪市')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('深市')" prop="shenShi">
            <el-input v-model="form.shenShi" :placeholder="$t('深市')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('北A')" prop="beiA">
            <el-input v-model="form.beiA" :placeholder="$t('北A')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('三方关联银行')" prop="thirdPartyRelatedBanks">
            <el-input v-model="form.thirdPartyRelatedBanks" :placeholder="$t('三方关联银行')" show-word-limit maxlength="100" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="$t('备注')" prop="remark">
            <el-input v-model="form.remark" type="textarea" :placeholder="$t('备注')" :maxlength="2000" show-word-limit />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right;">
      <save-btn has-permi="fund:account" />
    </div>
  </div>
</template>

<script>
import { saveFundSecurity, getFundSecurity } from '@/api/fund/security/fundSecurity'
export default {
  data() {
    return {
      form: {},
      // 遮罩层
      loading: false,
      // 表单校验
      rules: {
        securityCompany: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ], capitalAccount: [
          { required: true, message: this.$t('必填信息'), trigger: 'blur' }
        ] }
    }
  },
  created() {
  },
  methods: {
    // 初始化数据
    init(data) {
      this.loading = true
      if (data != null && data.id !== undefined) {
        getFundSecurity(data.id).then(response => {
          this.form = response.data
          this.loading = false
        })
      } else {
        this.reset()
        this.loading = false
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        fundId: this.$route.query.id,
        securityCompany: '',
        capitalAccount: undefined,
        huShi: undefined,
        shenShi: undefined,
        beiA: undefined,
        thirdPartyRelatedBanks: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined,
        fileList: []
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    // 关闭form页面
    closeForm() {
      // 关闭form页面遮罩层
      this.loading = false
      // 关闭form页面
      this.$parent.$parent.formOpen = false
      // 刷新list页面
      this.$parent.$parent.getList()
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          saveFundSecurity(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('保存成功'))
              this.closeForm()
            } else {
              this.msgError(response.msg)
            }
            this.loading = false
          })
        } else {
          this.locationError(document)
        }
      })
    }

  }

}
</script>
